class Story < ActiveRecord::Base
  validates_presence_of :name, :link
  has_many :votes
  has_many :comments
  belongs_to :user
  before_create :generate_permalink
  acts_as_taggable
  
  def latest_votes
    votes.find( :all, :order => 'id DESC', :limit => 3)
  end
  
  def votes_number
    votes.size.to_s
  end
  
  def comments_number
    comments.size.to_s
  end
  
  protected
  def generate_permalink
    self.permalink = name.downcase.gsub(/\W/, '-')
  end
end
